package week04;

public class T035 {
	public static boolean isPrime(int n) {
		if(n<2) return false;
		int sq=(int) Math.sqrt(n);
		for(int i=2;i<=sq;i++) {
			if(n%i==0) return false;
		}
		return true;
	}
	
	public static boolean iscirPrime(int n) {
		String s =Integer.toString(n);
		String s1;
		for(int i=0;i<s.length();i++) {
			s1 = s.substring(i)+s.substring(0,i);
			if(!isPrime(Integer.parseInt(s1))) 
				return false;
		}
		return true;
	}
	
	public static void main(String[] args) {
		int count=1;
		for(int i=3;i<=1000000;i+=2) {
			if(iscirPrime(i)) count++;
		}
		System.out.println(count);
	}
}
